package com.kbbywyclient.ui.adapter;

import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kbbywyclient.R;
import com.kbbywyclient.data.entity.MinePartnerDetailsData;
import com.kbbywyclient.ui.adapter.base.BaseAdapter;
import java.util.List;

/**
 * Created by Jiangzx on 2017/11/3 15:31.
 * 总代理合伙人统计明细
 */

public class PartnerDetailsAdapter1 extends BaseAdapter<MinePartnerDetailsData.MonthData>{
    private int selected=-1;
    public PartnerDetailsAdapter1(List<MinePartnerDetailsData.MonthData> data) {
        super(data, R.layout.item_partner_details_1);
    }

    @Override
    public void convert(Holder holder, MinePartnerDetailsData.MonthData bean, int position) {
        holder.setText(R.id.tv_date, bean.getEvery_month());
        holder.setText(R.id.tv_application,String.valueOf(bean.getInclude_num()));
        holder.setText(R.id.tv_settlement,String.valueOf(bean.getSettlement_num()));
        LinearLayout llDetails=holder.getView(R.id.ll_level_details);
        TextView tvDate=holder.getView(R.id.tv_date);
        if(position==selected){
            tvDate.setCompoundDrawablesWithIntrinsicBounds(null,
                    null,
                    ContextCompat.getDrawable(tvDate.getContext(),R.mipmap.icon_green_arrow_up),
                    null);
            llDetails.setVisibility(View.VISIBLE);
            holder.setText(R.id.tv_cell_0_0,"一级业务员"+bean.getOneLevelCount()+"个");
            holder.setText(R.id.tv_cell_0_1,String.valueOf(bean.getOneLevelIncluded()));
            holder.setText(R.id.tv_cell_0_2,String.valueOf(bean.getOneLevelSettlement()));

            holder.setText(R.id.tv_cell_1_0,"二级业务员"+bean.getTwoLevelCount()+"个");
            holder.setText(R.id.tv_cell_1_1,String.valueOf(bean.getTwoLevelIncluded()));
            holder.setText(R.id.tv_cell_1_2,String.valueOf(bean.getTwoLevelSettlement()));
        }else{
            tvDate.setCompoundDrawablesWithIntrinsicBounds(null,
                    null,
                    ContextCompat.getDrawable(tvDate.getContext(),R.mipmap.icon_green_arrow_down),
                    null);
            llDetails.setVisibility(View.GONE);
        }

        tvDate.setOnClickListener(v->{
            int temp=selected;
            if(temp!=-1){
                notifyItemChanged(temp);
            }
            if(selected==position){
                selected=-1;
                notifyItemChanged(position);
            }else{
                selected=position;
                notifyItemChanged(selected);
            }
        });
    }
}
